﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.Configuration;
using BaBaoFan.Modifier.Data;
using BaBaoFan.Modifier.Model;
using BaBaoFan.Modifier.Service;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;


namespace BaBaoFan.Modifier
{
    public class Startup
    {
        public Startup(Microsoft.Extensions.Configuration.IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public Microsoft.Extensions.Configuration.IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<DbSettings>(this.Configuration.GetSection("DbSettings"));

            services.AddScoped<DbConnection>();
            services.AddScoped<PmDbConnection>();
            services.AddScoped<IAlgorithmInfoRepository, AlgorithmInfoRepository>();
            services.AddScoped<IAlgorithmInfoService, AlgorithmInfoService>();
            services.AddScoped<IMillInfoRepository, MillInfoRepository>();
            services.AddScoped<IMillInfoService, MillInfoService>();
            services.AddScoped<IAlgorithmRepository, AlgorithmRepository>();
            services.AddScoped<IAlgorithmService, AlgorithmService>();
            services.AddScoped<ICoinInfoRepository, CoinInfoRepository>();
            services.AddScoped<ICoinInfoService, CoinInfoService>();
            services.AddScoped<IPoolRepository, PoolRepository>();
            services.AddScoped<IPoolService, PoolService>();
            services.AddScoped<INavigationRepository, NavigationRepository>();
            services.AddScoped<INavigationService, NavigationService>();
            services.AddScoped<INavigationRelationRepository, NavigationRelationRepository>();
            services.AddScoped<INavigationRelationService, NavigationRelationService>();
            services.AddScoped<IUserInfoRepository, UserInfoRepository>();
            services.AddScoped<IUserInfoService, UserInfoService>();

            services.AddMemoryCache();
            services.AddAutoMapper();//AutoMapper
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }

    }
}
